/*!
\copyright  Copyright (c) 2024 Qualcomm Technologies International, Ltd.
            All Rights Reserved.
            Qualcomm Technologies International, Ltd. Confidential and Proprietary.
\file
\brief      Configure between down-mixing or channel selection when converting stereo to mono audio.

This is the Kymera implementation of the API.

*/

#include "channel_mixing.h"

#include <kymera.h>
#include <kymera_data.h>
#include <kymera_volume.h>
#include <kymera_le_audio.h>

void ChannelMixing_SetStereoDownMix(bool stereo_down_mix)
{
   appKymeraSetStereoLeftRightMix(stereo_down_mix);
}

bool ChannelMixing_IsStereoDownMixEnabled(void)
{
   return KymeraGetTaskData()->enable_left_right_mix;
}

#ifdef INCLUDE_CIS_MIRRORING
static bool channelMixing_LeAudioSetMixerChannelGain(int gain_left, int gain_right)
{
    bool mixer_gain_set = FALSE;
    Operator mixer_op;

    if (GET_OP_FROM_CHAIN(mixer_op, KymeraGetTaskData()->chain_input_handle, OPR_LEFT_RIGHT_MIXER))
    {
       OperatorsMixerSetGains(mixer_op, gain_left, gain_right, GAIN_MIN);
       mixer_gain_set = TRUE;
    }

    return mixer_gain_set;
}
#endif /* INCLUDE_CIS_MIRRORING */

bool ChannelMixing_LeSetIsoChannelToRender(appKymeraLeAudioChannelType channel_mask)
{
#ifdef INCLUDE_CIS_MIRRORING
    bool channel_test_result = FALSE;
    kymeraTaskData *theKymera = KymeraGetTaskData();

    /* Channel selection should happen only if the LE audio chain is active. */
    if (theKymera->state == KYMERA_STATE_LE_AUDIO_ACTIVE)
    {
        int gain_left, gain_right;

        gain_left = channel_mask & KYMERA_LE_AUDIO_ISO_CHANNEL_LEFT ? GAIN_FULL : GAIN_MIN;
        gain_right = channel_mask & KYMERA_LE_AUDIO_ISO_CHANNEL_RIGHT ? GAIN_FULL : GAIN_MIN;

        channel_test_result = channelMixing_LeAudioSetMixerChannelGain(gain_left, gain_right);
    }

    return channel_test_result;
#else
        UNUSED(channel_mask);
        return FALSE;
#endif /* INCLUDE_CIS_MIRRORING */
}


